<?php

namespace App\Http\Controllers;

use App\Datatables;
use App\MarketList;
use Illuminate\Http\Request;
use QrCode;

/**
 * Class MarketRoteryController
 * @package App\Http\Controllers
 */
class MarketRoteryController extends Controller
{
    /**
     * MarketRoteryController constructor.
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * 超市列表
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
     */
    public function marketList(Request $request)
    {
        if ($request->isMethod('post')) {
            return response()->json(Datatables::MarketList());
        }

        return view('marketRotery.marketList');
    }

    /**
     * 添加超市
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function marketPublish(Request $request)
    {
        return response()->json(MarketList::MarketPublish($request));
    }

    /**
     * 超市详情
     * @param MarketList $marketList
     * @return \Illuminate\Http\JsonResponse
     */
    public function marketInfo(MarketList $marketList)
    {
        return response()->json([
            'title' => $marketList->title,
            'mobile' => $marketList->mobile,
            'remarks' => $marketList->remarks,
        ]);
    }

    public function marketModify(Request $request, MarketList $marketList)
    {
        return response()->json(MarketList::MarketModify($marketList, $request));
    }

}
